package com.sa.token.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.sa.token.dto.request.user.DelUserRequest;
import com.sa.token.dto.request.user.UserPageRequest;
import com.sa.token.message.StandardResponse;
import com.sa.token.service.SysUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @desc：
 * @author： xhs
 * @date： 2021/9/7 22:24
 * @version： JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private SysUserService userService;

    /**
     * 分页查询用户信息
     *
     * @param userPageRequest
     * @return
     */
    @PostMapping("/queryUser")
    public StandardResponse queryUser(@Valid @RequestBody UserPageRequest userPageRequest) {
        StandardResponse response = userService.queryUser(userPageRequest);
        return response;
    }


    /**
     * 删除用户
     *
     * @param delUserRequest
     * @return
     */
    @PostMapping("/delUser")
    public StandardResponse delUser(@Valid @RequestBody DelUserRequest delUserRequest) {
        StandardResponse response = userService.delUser(delUserRequest);
        return response;
    }

    /**
     * 冻结账号
     *
     * @param delUserRequest
     * @return
     */
    @PostMapping("/frozenAccount")
    public StandardResponse frozenAccount(@Valid @RequestBody DelUserRequest delUserRequest) {
        StandardResponse response = userService.frozenAccount(delUserRequest);
        return response;
    }

    /**
     * 解冻账号
     *
     * @param delUserRequest
     * @return
     */
    @PostMapping("/thawAccount")
    public StandardResponse thawAccount(@Valid @RequestBody DelUserRequest delUserRequest) {
        StandardResponse response = userService.thawAccount(delUserRequest);
        return response;
    }

    /**
     * 根据登录账号查询权限
     *
     * @return
     */
    @PostMapping("/getUserAuthority")
    public StandardResponse getUserAuthority() {
        StandardResponse response = userService.getUserAuthority();
        return response;
    }

}
